All Questions
14 questions
9votes
2answers
1kviews
Implementation of Viterbi algorithm along with unit tests
Introduction to the Algorithm A system can be in N different, unobservable states, (i.e, we never know in which state the system actually is). The system also has a finite number of possible ...
3votes
3answers
461views
A tiny Java library for generating Gray codes
This library is for generating Gray codes. A Gray code over \$n\$ bits is a list of \$2^n\$ different \$n\$-bit strings subject to the following constraint: two adjacent bit string differ in only one ...
6votes
1answer
127views
Benchmarking efficient inversion counting algorithms in Java
Given an array \$A = (a_1, a_2, \dots, a_n)\$, the number of inversions in \$A\$ is the number of index pairs \$i,j\$ (\$i < j\$) such that \$a_i > a_j\$. We can find the number of inversions in ...
2votes
0answers
677views
A fast integer key map in Java via a van Emde Boas tree
Introduction The following data structure is a dictionary mapping primitive int values to any value type. Basically, under the hood it is a hash table, where a ...
1vote
1answer
891views
Generic trie implementation in Java
I implemented a Trie data structure in Java, to test my understanding of the concept. I tried (pun intended :) ) to follow TDD steps along the way (i.e., add first a failing test case, and implement ...
4votes
1answer
208views
Algorithms to find various kinds of paths in graphs
I think many here are familiar with the graph data structure. Not very long ago, I implemented as an exercise a supposedly simple Graph application that does some traversals. To note, the most complex ...
7votes
3answers
873views
Nucleotide Count
I am learning Java and hence practicing it from here. The solution seems pretty trivial to me but still I would like to have a honest review which would guide me to following ideas: Am I maintaining ...
5votes
1answer
569views
Test whether target string is substring of source string
The code is self-explanatory. It has \$O(n)\$ complexity, and it tells whether a given string is the substring of the source string. Are there any cases where this algorithm fails? Is there anything ...
4votes
1answer
189views
Are AVL trees equal? - revision 3
The original question Given two binary trees, return true if they are structurally identical, and false otherwise. Are AVL trees equal? Are AVL trees equal? - revision 2 This revision on GitHub ...
1vote
1answer
189views
Are AVL trees equal? - revision 2
Revision 1. This revision on GitHub In addition to the solution itself, I wrote tests for all the possible cases. It seems you have verified all execution paths are covered. You are right. ...
8votes
1answer
774views
Are AVL trees equal?
I was inspired by this answer and decided to implement an AVL tree with the methods equals and hashCode as if I was asked to do ...
5votes
2answers
467views
Longest substring with unique characters
Find the length of the longest substring without repeating characters Any comments on my code? ...
3votes
2answers
2kviews
Radix sort with integer divisions
Here's a perhaps naive but simple implementation of Radix sort in Java. It works with any radix, and both positive and negative numbers. ...
4votes
1answer
134views
TDD and use case: cook dish with substitutions
This is code for a class that takes available ingredients and returns left over ingredients after making a dish. Cesars: 2 carrot 4 ice burg 1 chicken 1 beans Russian: 2 carrots 2 beans 2 chicken If ...